package com.config;

import org.apache.commons.dbcp.BasicDataSource;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;

@Configuration
public class MyBatisConfig {
    @Bean
    public BasicDataSource getBasicDataSource() {
        BasicDataSource basicDataSource = new BasicDataSource();
        basicDataSource.setDriverClassName("com.mysql.cj.jdbc.Driver");
        basicDataSource.setUrl("jdbc:mysql://localhost:3306/smbms");
        basicDataSource.setUsername("root");
        basicDataSource.setPassword("gzx123zyl920");
        return basicDataSource;
    }

    @Bean
    public SqlSessionFactoryBean getSqlSessionFactory() {
        SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
        sqlSessionFactoryBean.setDataSource(getBasicDataSource());
        sqlSessionFactoryBean.setTypeAliasesPackage("com.pojo");

//        sqlSessionFactoryBean.setMapperLocations();

        return sqlSessionFactoryBean;
    }
}
